home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / gs24src.zip / IINIT.C < prev    next >
C/C++ Source or Header  |  1992-03-16  |  7KB  |  212 lines

  1. /* Copyright (C) 1989, 1992 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* iinit.c */
  21. /* Initialize internally known objects for Ghostscript interpreter */
  22. #include "string_.h"
  23. #include "ghost.h"
  24. #include "alloc.h"
  25. #include "dict.h"
  26. #define INCLUDE_ERROR_NAMES        /* see errors.h */
  27. #include "errors.h"
  28. #include "name.h"
  29. #include "oper.h"
  30. #include "save.h"            /* for alloc_refs */
  31. #include "store.h"
  32.  
  33. /* Implementation parameters. */
  34. /* The size of systemdict can be set in the makefile. */
  35. #ifndef SYSTEMDICT_SIZE
  36. #  define SYSTEMDICT_SIZE 449        /* a nice prime (?) number */
  37. #endif
  38. #define systemdict_size SYSTEMDICT_SIZE
  39. #define op_array_table_size 100        /* arbitrary */
  40.  
  41. /* Standard dictionaries */
  42. ref name_errordict;
  43. /* Error names */
  44. ref name_ErrorNames;
  45.  
  46. /* The operator tables */
  47. op_def_ptr *op_def_table;
  48. uint op_def_count;
  49. ref op_array_table;    /* t_array, definitions of `operator' procedures */
  50. ushort *op_array_nx_table;        /* name indices for same */
  51. uint op_array_count;
  52.  
  53. /* Enter a name and value into systemdict */
  54. void
  55. initial_enter_name(const char *nstr, ref *pref)
  56. {    ref nref;
  57.     name_enter(nstr, &nref);
  58.     if ( dict_put(&systemdict, &nref, pref) )
  59.         lprintf("dict_put failed!\n"),
  60.         gs_exit(1);
  61. }
  62.  
  63. /* Initialize objects other than operators */
  64. void
  65. obj_init()
  66. {
  67.     /* Initialize the standard objects */
  68.     ref vmark, vnull;
  69.     make_tv(&vmark, t_mark, intval, 0);
  70.     make_tv(&vnull, t_null, intval, 0);
  71.  
  72.     /* Create the system dictionary */
  73.     dict_create(systemdict_size, &systemdict);
  74.     dstack[1] = dstack[0];        /* just during initialization */
  75.  
  76.     /* Initialize the predefined names other than operators */
  77.     initial_enter_name("mark", &vmark);
  78.     initial_enter_name("null", &vnull);
  79.  
  80.     /* Create other system-known names */
  81.     name_enter("errordict", &name_errordict);
  82.     name_enter("ErrorNames", &name_ErrorNames);
  83.  
  84.     /* Create the error name table */
  85.        {    int n = sizeof(gs_error_names) / sizeof(char _ds *) - 1;
  86.         int i;
  87.         ref era;
  88.         make_tasv(&era, t_array, a_read + a_execute, n, refs,
  89.               alloc_refs(n, "obj_init(ErrorNames)"));
  90.         for ( i = 0; i < n; i++ )
  91.           name_enter((char *)gs_error_names[i], era.value.refs + i);
  92.         dict_put(&systemdict, &name_ErrorNames, &era);
  93.        }
  94. }
  95.  
  96. /* Optional devices are handled in gconfig.c. */
  97. #define device_(dev)
  98.  
  99. /* Initialize the operators */
  100. #define oper_(defs) defs[],
  101.     /* Non-graphics operators */
  102. extern op_def
  103. #include "gconfig.h"
  104.   interp_op_defs[],
  105.   zarith_op_defs[], zarray_op_defs[], zcontrol_op_defs[],
  106.   zdict_op_defs[], zfile_op_defs[], zfileio_op_defs[],
  107.   zfilter_op_defs[], zgeneric_op_defs[],
  108.   zmath_op_defs[], zmisc_op_defs[], zpacked_op_defs[], zprops_op_defs[],
  109.   zrelbit_op_defs[], zstack_op_defs[], zstring_op_defs[],
  110.   ztype_op_defs[], zvmem_op_defs[],
  111.     /* Graphics operators */
  112.   zchar_op_defs[], zcolor_op_defs[], zdevice_op_defs[],
  113.   zfont_op_defs[], zfont1_op_defs[], zfont2_op_defs[],
  114.   zgstate_op_defs[], zht_op_defs[],
  115.   zmatrix_op_defs[], zpaint_op_defs[], zpath_op_defs[],
  116.   zpath2_op_defs[];
  117. #undef oper_
  118. #define oper_(defs) defs,
  119. private op_def_ptr op_defs_all[] = {
  120. #include "gconfig.h"
  121.     /* Non-graphics operators */
  122.   interp_op_defs,
  123.   zarith_op_defs, zarray_op_defs, zcontrol_op_defs,
  124.   zdict_op_defs, zfile_op_defs, zfileio_op_defs,
  125.   zfilter_op_defs, zgeneric_op_defs,
  126.   zmath_op_defs, zmisc_op_defs, zpacked_op_defs, zprops_op_defs,
  127.   zrelbit_op_defs, zstack_op_defs, zstring_op_defs,
  128.   ztype_op_defs, zvmem_op_defs,
  129.     /* Graphics operators */
  130.   zchar_op_defs, zcolor_op_defs, zdevice_op_defs,
  131.   zfont_op_defs, zfont1_op_defs, zfont2_op_defs,
  132.   zgstate_op_defs, zht_op_defs,
  133.   zmatrix_op_defs, zpaint_op_defs, zpath_op_defs,
  134.   zpath2_op_defs,
  135.     /* end marker */
  136.   (op_def_ptr)0
  137. };
  138. #undef oper_
  139. #undef device_
  140.  
  141. /* Run the initialization procedures of the individual operator files. */
  142. void
  143. zop_init()
  144. {    op_def_ptr _ds *tptr;
  145.     op_def_ptr def;
  146.     for ( tptr = op_defs_all; *tptr != 0; tptr++ )
  147.        {    for ( def = *tptr; def->oname != 0; def++ ) ;
  148.         if ( def->proc != 0 )
  149.             ((void (*)(P0()))(def->proc))();
  150.        }
  151. }
  152. /* Initialize the operator table. */
  153. void
  154. op_init()
  155. {    int count = 1;
  156.     op_def_ptr _ds *tptr;
  157.     op_def_ptr def;
  158.     char _ds *nstr;
  159.  
  160.     /* Do a first pass just to count the operators. */
  161.  
  162.     for ( tptr = op_defs_all; *tptr != 0; tptr ++ )
  163.      for ( def = *tptr; def->oname != 0; count++, def++ )
  164.       ;
  165.  
  166.     /* Do a second pass to construct the operator table, */
  167.     /* and enter the operators in systemdict. */
  168.  
  169.     op_def_table = (op_def_ptr *)alloc(count, sizeof(op_def_ptr),
  170.                        "op_init(op_def_table)");
  171.     op_def_count = count;
  172.     count = 1;
  173.     for ( tptr = op_defs_all; *tptr != 0; tptr ++ )
  174.      for ( def = *tptr; (nstr = def->oname) != 0; count++, def++ )
  175.        {    ref nref, oper;
  176.         make_oper(&oper, count, (dummy_op_proc_p)(def->proc));
  177.         interp_fix_op(&oper);        /* optimize if possible */
  178.         /* The first character of the name is a digit */
  179.         /* giving the minimum acceptable number of operands. */
  180.         /* For now, we just skip over it. */
  181.         nstr++;
  182.         /* Don't enter internal operators into systemdict. */
  183.         if ( *nstr == '%' )
  184.             name_enter(nstr, &nref);
  185.         else
  186.             initial_enter_name(nstr, &oper);
  187.         if ( def->oindex != 0 )
  188.             *def->oindex = count;
  189.         op_def_table[count] = def;
  190.        }
  191.  
  192.     /* Allocate the table for `operator' procedures. */
  193.        {    ref *tbody =
  194.           alloc_refs(op_array_table_size, "op_array table");
  195.         make_tasv(&op_array_table, t_array, a_read+a_execute,
  196.               op_array_table_size, refs, tbody);
  197.         refset_null(tbody, op_array_table_size);
  198.         op_array_nx_table =
  199.           (ushort *)alloc(op_array_table_size, sizeof(ushort),
  200.                   "op_array nx table");
  201.         op_array_count = 0;
  202.        }
  203.  
  204. }
  205.  
  206. /* Initialize variables that hold name constants. */
  207. void
  208. init_names(register const names_def _ds *pnd)
  209. {    for ( ; pnd->vname != 0; pnd++ )
  210.         name_enter(pnd->vname, pnd->pvref);
  211. }
  212.